import axios from 'axios'
import { ElLoading } from 'element-plus'

let loading

const startLoading = () => {
  const options = {
    lock: true,
    test: '加载中...',
    background: 'rgba(0,0,0,0.7)'
  }
  loading = ElLoading.service(options)
}

const endLoading = () => {
  loading.close()
}
// 请求拦截
axios.interceptors.request.use(config => {
  startLoading()
  return config
})

// 响应拦截
axios.interceptors.response.use(response => {
  endLoading()
  return response
}, error => {
  // 错误提醒
  return Promise.reject(error)
})

export default axios
